// packageG/mycomponent/flashSaleCoupon/flashSaleCoupon.js
const app = getApp();
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    datas: {
      type: null
    },
    component_id: {
      type: null
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    nowTime: null
  },
  lifetimes: {
    attached() {
      let nowTime = (new Date().getTime() / 1000).toFixed(0);
      this.setData({
        nowTime: nowTime
      })
      let language = wx.getStorageSync("langIndex");
      this.setData({
        language: language.en
      });
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    async toOrder(e) {
      let {
        item
      } = e.currentTarget.dataset;
      let json = {
        address: "",
        goods: `[{"goods_id":${item.goods_id},"total":1,"option_id":"0"}]`,
        member_coupon_ids: "[]",
        orders: "[]",
        invoice: {},
        mark: 0,
        dispatch_type_id: 1,
        first_default: "",
        cart_ids: "[]",
        positioning_success: 0,
        province: "",
        city: ""
      };
      if (!item.coupon.coupon_restrict) {
        // 需要绑定车牌
        wx.navigateTo({
          url: '/mircoApp/new_coupon/carNumber/carNumber?id=' + item.id + '&orderGoodsId=' + item.goods_id,
        })
        return;
      }
      let {
        data
      } = await app._postNetWork({
        url: app.getNetAddresss("plugin.new-coupon.frontend.controllers.flash-sale.index"),
        data: json
      })
      if (data.result) {
        wx.navigateTo({
          url: '/packageD/buy/orderPay/orderPay?order_id=' + data.data.order_ids,
        })
      } else {
        app.tips(data.msg);
      }
    },
  }
})